package com.itcoon.cloud.framework.security.config;

import com.itcoon.cloud.framework.security.advice.JwtHttpSecurityAdvice;
import com.itcoon.cloud.framework.security.handler.JwtAuthenticationSuccessHandler;
import com.itcoon.cloud.framework.security.handler.TokenLogoutHandler;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.AuthenticationEntryPoint;

@AutoConfiguration
public class SecurityBeanConfig{

    @Bean
    public JwtAuthenticationSuccessHandler jwtAuthenticationSuccessHandler(ApplicationEventPublisher eventPublisher){
        return new JwtAuthenticationSuccessHandler(eventPublisher);
    }

    @Bean
    public TokenLogoutHandler tokenLogoutHandler(){
        return new TokenLogoutHandler();
    }

    @Bean
    public JwtHttpSecurityAdvice jwtHttpSecurityAdvice(AuthenticationEntryPoint entryPoint, UserDetailsService userDetailsService){
        return new JwtHttpSecurityAdvice(entryPoint, userDetailsService);
    }
}
